package com.ruoyi.web.controller.productionre;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.production.domain.GraftingclipReturn;
import com.ruoyi.production.domain.SimpleProduction;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.production.domain.GraftinglabelReturn;
import com.ruoyi.production.service.IGraftinglabelReturnService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 嫁接签退回Controller
 *
 * @author ruoyi
 * @date 2021-07-20
 */
@Api("嫁接签退回")
@RestController
@RequestMapping("/production/graftinglabelre")
public class GraftinglabelReturnController extends BaseController
{
    @Autowired
    private IGraftinglabelReturnService graftinglabelReturnService;

    /**
     * 查询嫁接签退回列表
     */
    @ApiOperation("查询嫁接签退回列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:graftinglabelre:list')")
    @GetMapping("/list")
    public TableDataInfo list(GraftinglabelReturn graftinglabelReturn)
    {
        startPage();
        List<GraftinglabelReturn> list = graftinglabelReturnService.selectGraftinglabelReturnList(graftinglabelReturn);
        return getDataTable(list);
    }

    /**
     * 导出嫁接签退回列表
     */
    @ApiOperation("导出嫁接签退回列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:graftinglabelre:export')")
    @Log(title = "嫁接签退回", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GraftinglabelReturn graftinglabelReturn)
    {
        List<GraftinglabelReturn> list=new ArrayList();
        //通过id来取
        Long a[]=graftinglabelReturn.getGraftinglabelReturnIds();
        for(int i=0;i<a.length;i++) {
            GraftinglabelReturn list1 = graftinglabelReturnService.selectGraftinglabelReturnById(a[i]);
            list.add(list1);
        }

        ExcelUtil<GraftinglabelReturn> util = new ExcelUtil<GraftinglabelReturn>(GraftinglabelReturn.class);
        return util.exportExcel(list, "嫁接签退回数据");
    }

    /**
     * 获取嫁接签退回详细信息
     */
    @ApiOperation("获取嫁接签退回详细信息")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:graftinglabelre:query')")
    @GetMapping(value = "/{graftinglabelReturnId}")
    public AjaxResult getInfo(@PathVariable("graftinglabelReturnId") Long graftinglabelReturnId)
    {
        return AjaxResult.success(graftinglabelReturnService.selectGraftinglabelReturnById(graftinglabelReturnId));
    }

    /**
     * 新增嫁接签退回
     */
    @ApiOperation("新增嫁接签退回")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:graftinglabelre:add')")
    @Log(title = "嫁接签退回", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GraftinglabelReturn graftinglabelReturn)
    {
        return toAjax(graftinglabelReturnService.insertGraftinglabelReturn(graftinglabelReturn));
    }

    /**
     * 修改嫁接签退回
     */
    @ApiOperation("修改嫁接签退回")
    @ResponseBody
    @PreAuthorize("@ss.hasAnyPermi('production:graftinglabelre:edit,production:graftinglabelre:permit')")
    @Log(title = "嫁接签退回", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GraftinglabelReturn graftinglabelReturn)
    {
        return toAjax(graftinglabelReturnService.updateGraftinglabelReturn(graftinglabelReturn));
    }

    /**
     * 删除嫁接签退回
     */
    @ApiOperation("删除嫁接签退回")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:graftinglabelre:remove')")
    @Log(title = "嫁接签退回", businessType = BusinessType.DELETE)
	@DeleteMapping("/{graftinglabelReturnIds}")
    public AjaxResult remove(@PathVariable Long[] graftinglabelReturnIds)
    {
        return toAjax(graftinglabelReturnService.deleteGraftinglabelReturnByIds(graftinglabelReturnIds));
    }

    /**
     * 获取嫁接签类型下拉框
     */
    @ApiOperation("获取嫁接签类型下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:graftinglabelre:type')")
    @GetMapping("/type")
    public TableDataInfo getType(){

        List<GraftinglabelReturn> list = graftinglabelReturnService.getGraftinglabelType();
        List<SimpleProduction> simpleProductions = new ArrayList<>();
        for (GraftinglabelReturn graftinglabelReturn:list) {
            Long id = graftinglabelReturn.getGraftinglabelTypeId();
            String name = graftinglabelReturn.getGraftinglabelType();
            SimpleProduction simpleProduction = new SimpleProduction(id,name);
            simpleProductions.add(simpleProduction);
        }
        return getDataTable(simpleProductions);
    }

    /**
     * 获取用户列表下拉框
     */
    @ApiOperation("获取用户列表下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:graftinglabelre:username')")
    @GetMapping("/username")
    public TableDataInfo getUserName(){

        List<GraftinglabelReturn> list = graftinglabelReturnService.getUserName();
        List<SimpleProduction> simpleProductions = new ArrayList<>();
        for (GraftinglabelReturn graftinglabelReturn:list) {
            Long id = graftinglabelReturn.getUserId();
            String name = graftinglabelReturn.getUserName();
            SimpleProduction simpleProduction = new SimpleProduction(id,name);
            simpleProductions.add(simpleProduction);
        }
        return getDataTable(simpleProductions);
    }

    /**
     * 获取规格下拉框
     */
    @ApiOperation("获取规格下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:graftinglabelre:specification')")
    @GetMapping("/specification/{graftinglabelTypeId}")
    public TableDataInfo getSpecification(@PathVariable("graftinglabelTypeId") Long graftinglabelTypeId){

        List<String> list = graftinglabelReturnService.getgraftinglabelSpecification(graftinglabelTypeId);
        return getDataTable(list);
    }

    /**
     * 获取公司下拉框
     */
    @ApiOperation("获取公司下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:graftinglabelre:origincompany')")
    @GetMapping("/origincompany/{graftinglabelTypeId}")
    public TableDataInfo getOriginCompany(@PathVariable("graftinglabelTypeId") Long graftinglabelTypeId){

        List<String> list = graftinglabelReturnService.getOriginCompany(graftinglabelTypeId);
        return getDataTable(list);
    }
}
